﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Artem.Google.UI;

namespace VO.Web.Utils
{
    public class GeoUtils2
    {
        public static void GetCenterAndBounds(GooglePolyline polLine, out double latMin, out double latMax, out double lonMin, out double lonMax, out double latCenter, out double lonCenter)
        {
            double _latMin = 180.01;
            double _lonMax = -180;
            double _latMax = -180;
            double _lonMin = 180.01;
            polLine.Points.ForEach(delegate(GoogleLocation p)
            {
                _latMin = Math.Min(_latMin, p.Latitude);
                _latMax = Math.Max(_latMax, p.Latitude);
                _lonMin = Math.Min(_lonMin, p.Longitude);
                _lonMax = Math.Max(_lonMax, p.Longitude);
            }
                );

            latCenter = (_latMin + _latMax) / 2;
            lonCenter = (_lonMin + _lonMax) / 2;

            latMin = _latMin;
            lonMax = _lonMax;
            latMax = _latMax;
            lonMin = _lonMin;
        }
    }
}